import Vue from 'vue'
import Vuex from 'vuex'
import cloneDeep from 'lodash/cloneDeep'
import personal from './modules/personal'
import media from './modules/media'
import elective from './modules/elective'
import score from './modules/score'
import user from './modules/user'
import share from './modules/share'

Vue.use(Vuex)

export default new Vuex.Store({
  namespaced: true,
  state: {
    version: '1.0.1.0', // 版本控制用于刷除原有缓存
    device: '', // APP/WX/H5
    gsign: '', // 微信渠道
    uniacid: '', // 微信ID
    openid: '' // 微信OPENID
  },
  modules: {
    personal,
    elective,
    score,
    user,
    share,
    media
  },
  mutations: {
    // 重置vuex本地储存状态
    resetStore (state) {
      Object.keys(state).forEach((key) => {
        state[key] = cloneDeep(window.SITE_CONFIG['storeState'][key])
      })
    }
  }
})
